<%@ Page Language="C#" MasterPageFile="~/Base.Master" AutoEventWireup="true" CodeBehind="FinancialCards.aspx.cs" Inherits="SVAccountingWebUI.FinancialCards" %>
<%@ MasterType VirtualPath="~/Base.Master"  %>

<asp:Content ID="FinancialCards" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">

    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
        AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="CardId" 
        DataSourceID="FinancialCardsLinqDataSource"
        onrowcancelingedit="gv_RowCancelingEdit" 
        onrowdeleting="gv_RowDeleting" onrowediting="gv_RowEditing"
        >
        <Columns>
            <asp:TemplateField ShowHeader="False">
                <EditItemTemplate>
                    <asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="True" 
                        CommandName="Update" ImageUrl="~/Icons/Update.png" Text="Update" />
                    &nbsp;<asp:ImageButton ID="ImageButton2" runat="server" CausesValidation="False" 
                        CommandName="Cancel" ImageUrl="~/Icons/Cancel.png" Text="Cancel" />
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="False" 
                        CommandName="Edit" ImageUrl="~/Icons/Edit.png" Text="Edit" />
                    &nbsp;<asp:ImageButton ID="DeleteButton" runat="server" CausesValidation="False" 
                        CommandName="Delete" ImageUrl="~/Icons/delete.png" Text="Delete"
                        message="<%$ Resources:Resource, DeleteConfirm %>" 
                        OnClientClick='return confirm(this.getAttribute("message"))'
                        />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="CardId" HeaderText="CardId" ReadOnly="True" 
                SortExpression="CardId" />
            <asp:BoundField DataField="ComintenttAccountID" 
                HeaderText="ComintenttAccountID" SortExpression="ComintenttAccountID" />
            <asp:BoundField DataField="OwnerAccountID" HeaderText="OwnerAccountID" 
                SortExpression="OwnerAccountID" />
            <asp:BoundField DataField="Debit" HeaderText="Debit" SortExpression="Debit" />
            <asp:BoundField DataField="Credit" HeaderText="Credit" 
                SortExpression="Credit" />
            <asp:BoundField DataField="DateCreated" HeaderText="DateCreated" 
                SortExpression="DateCreated" />
            <asp:TemplateField HeaderText="CreatorId" SortExpression="CreatorId">
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" 
                        Text='<%# Bind("rAccountantPerson.Person.FirstName") %>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:Label ID="Label1" runat="server" 
                        Text='<%# Bind("rAccountantPerson.Person.FirstName") %>'></asp:Label>
                </EditItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    
    <asp:LinqDataSource ID="FinancialCardsLinqDataSource" runat="server" 
        ContextTypeName="SVAccountingBL.SVALinqDataContext" EnableDelete="True" 
        EnableInsert="True" EnableUpdate="True" TableName="FinancialCards"
        ondeleted="LinqDataSource_Deleted" 
        onupdated="LinqDataSource_Updated" 
        oninserted="LinqDataSource_Inserted" 
        oninserting="LinqDataSource_Inserting"
        
        >
    </asp:LinqDataSource>
    
    <asp:LinqDataSource ID="CompaniesLinqDataSource" runat="server" 
        ContextTypeName="SVAccountingBL.SVALinqDataContext" 
        Select="new (CompanyID, CompanyName, CompanyAccounts)" TableName="Companies">
    </asp:LinqDataSource>
    
    
    
    <asp:UpdatePanel ID="AddNewPanel" runat="server">
   <ContentTemplate>
    <br />
    <asp:LinkButton ID="lbtnAddNew" runat="server" 
                    Text="<%$ Resources:Resource, AddNew %>" 
           onclick="AddNew_Click"/>
    <br />
    <br />
   <div ID="InsertDiv" runat="server" visible="false">
       <%--DataSourceID="FinancialCardsLinqDataSource" --%>
       <asp:DetailsView ID="dvInsertFinantialCard" runat="server" 
           AutoGenerateRows="False" DataKeyNames="CardId" 
           DefaultMode="Insert" Height="50px" 
           Width="125px"
           onitemcommand="InsertDV_ItemCommand" CellPadding="4" ForeColor="#333333" 
           GridLines="None" oniteminserted="dvInsertFinantialCard_ItemInserted" 
           oniteminserting="dvInsertFinantialCard_ItemInserting" onmodechanging="dvInsertFinantialCard_ModeChanging"
           >
           <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
           <CommandRowStyle BackColor="#FFFFC0" Font-Bold="True" />
           <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
           <FieldHeaderStyle BackColor="#FFFF99" Font-Bold="True" />
           <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
           <Fields>
               
               <asp:BoundField DataField="CardId" HeaderText="CardId" InsertVisible="False" 
                   ReadOnly="True" SortExpression="CardId" />
               <asp:TemplateField HeaderText="ComintenttAccountID" 
                   SortExpression="ComintenttAccountID">
                   <EditItemTemplate>
                       <asp:TextBox ID="TextBox1" runat="server" 
                           Text='<%# Bind("ComintenttAccountID") %>'></asp:TextBox>
                   </EditItemTemplate>
                   <InsertItemTemplate>
                   <table>
                   <tr>
                   <td>
                       Company : 
                   </td>
                   <td>
                   <asp:DropDownList ID="ddlCommitentCompanies" runat="server" AutoPostBack="True" 
                           DataSourceID="CompaniesLinqDataSource" DataTextField="CompanyName" 
                           DataValueField="CompanyID" 
                           onselectedindexchanged="ddlCommitentCompanies_SelectedIndexChanged" AppendDataBoundItems="true">
                           <asp:ListItem Text="--Select Company --" Value="-1" Selected="True" />
                       </asp:DropDownList>
                   </td>
                   </tr>
                   
                   <tr>
                   <div id="dvComintentAccount" runat="server" visible= "false">
                   <td>
                        Account :
                   </td>
                   <td>
                    <asp:DropDownList ID="ddlComintenttAccount" runat="server" />
                   </td>
                   </div>
                   </tr>
                   </table>
                   </InsertItemTemplate>
                   <ItemTemplate>
                       <asp:Label ID="Label1" runat="server" Text='<%# Bind("ComintenttAccountID") %>'></asp:Label>
                   </ItemTemplate>
               </asp:TemplateField>
               <asp:TemplateField HeaderText="OwnerAccountID" SortExpression="OwnerAccountID">
                   <EditItemTemplate>
                       <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("OwnerAccountID") %>'></asp:TextBox>
                   </EditItemTemplate>
                   <InsertItemTemplate>
                   <table>
                   <tr>
                   <td>
                       Company : 
                   </td>
                   <td>
                   <asp:DropDownList ID="ddlOwnerCompanies" runat="server" AutoPostBack="True" 
                           DataSourceID="CompaniesLinqDataSource" DataTextField="CompanyName" 
                           DataValueField="CompanyID" 
                           onselectedindexchanged="ddlOwnersCompanies_SelectedIndexChanged" AppendDataBoundItems="true">
                           <asp:ListItem Text="--Select Company --" Value="-1" Selected="True" />
                       </asp:DropDownList>
                   </td>
                   </tr>
                   
                   <tr>
                   <div id="dvOwnerAccount" runat="server" visible= "false">
                   <td>
                        Account :
                   </td>
                   <td>
                    <asp:DropDownList ID="ddlOwnerAccount" runat="server" />
                   </td>
                   </div>
                   </tr>
                   </table>
                   </InsertItemTemplate>
                   <ItemTemplate>
                       <asp:Label ID="Label2" runat="server" Text='<%# Bind("OwnerAccountID") %>'></asp:Label>
                   </ItemTemplate>
               </asp:TemplateField>
               <asp:BoundField DataField="ComintenttAccountID" 
                   HeaderText="ComintenttAccountID" SortExpression="ComintenttAccountID" InsertVisible="false" />
               <asp:BoundField DataField="Credit" HeaderText="Credit" InsertVisible="false"
                   SortExpression="Credit" />
               <asp:BoundField DataField="DateCreated" HeaderText="DateCreated" 
                   SortExpression="DateCreated" InsertVisible ="false" />
               <asp:BoundField DataField="CreatorId" HeaderText="CreatorId" InsertVisible="false"
                   SortExpression="CreatorId" />
               <asp:CommandField ButtonType="Image" CancelImageUrl="~/Icons/Cancel.png" 
                   InsertImageUrl="~/Icons/Add.png" ShowInsertButton="True" />
           </Fields>
           <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
           <AlternatingRowStyle BackColor="White" />
       </asp:DetailsView>
       
    </div>
    </ContentTemplate>
    
    <Triggers>
         <asp:AsyncPostBackTrigger ControlID="lbtnAddNew" EventName="click" />
         <asp:PostBackTrigger ControlID="dvInsertFinantialCard" /> 
    </Triggers>
    
   </asp:UpdatePanel>


</asp:Content>